package one.stand.controller;

import one.stand.entity.TokenEntity;
import one.stand.model.CompanyModel;
import one.stand.model.ResultModel;
import one.stand.request.GetWxPhoneRequest;
import one.stand.request.GlobalConfigurationRequest;
import one.stand.request.SendSmsCodeRequest;
import one.stand.request.WxLoginRequest;
import one.stand.response.BusinessCardResponse;
import one.stand.response.GlobalConfigurationResponse;
import one.stand.response.LoginResponse;
import one.stand.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@RequestMapping("home")
@RestController
public class HomeController {
    @Autowired
    private HomeService homeService;

    @PostMapping("batchDelToken")
    public ResultModel<Boolean> batchDelToken(@RequestParam(value="ids") Long[] ids) {
        return homeService.batchDelToken(ids);
    }

    /**
     * 登陆信息验证
     *
     * @param token
     * @return
     */
    @PostMapping("getLoginInfo")
    public ResultModel<TokenEntity> getLoginInfo(@RequestBody String token) {
        return homeService.getLoginInfo(token);
    }

    /**
     * 微信pc登陆
     *
     * @return
     */
    @PostMapping("getPcLoginImg")
    public ResultModel<String> getPcLoginImg(@RequestParam(value="companyKey") String companyKey) {
        return homeService.getPcLoginImg(companyKey);
    }

    @PostMapping("getWxPhone")
    public ResultModel<String> getWxPhone(@RequestBody GetWxPhoneRequest request) {
        return homeService.getPhone(request);
    }

    @PostMapping("initial")
    public ResultModel<List<GlobalConfigurationResponse>> initial(@RequestBody GlobalConfigurationRequest request) {
        return ResultModel.success(homeService.initial(request));
    }

    /**
     * 登陆验证
     *
     * @param token
     * @return
     */
    @PostMapping("loginVerification")
    public ResultModel<Boolean> loginVerification(@RequestBody String token) {
        return homeService.loginVerification(token);
    }

    /**
     * 扫码登陆验证
     *
     * @param code
     * @param state
     * @return
     */
    @PostMapping("pcLoginCallBack")
    public ResultModel<LoginResponse> pcLoginCallBack(@RequestParam(value="code") String code, @RequestParam(value="state") String state) {
        return homeService.pcLoginCallBack(code, state);
    }

    @PostMapping("userInfo")
    public ResultModel<BusinessCardResponse> userInfo(Long userId) {
        return homeService.userInfo(userId);
    }

    @PostMapping("loginByWeixin")
    public ResultModel<LoginResponse> wxLogin(@RequestBody WxLoginRequest request) {
        ResultModel<LoginResponse> result = homeService.loginByWeixin(request);
        return result;
    }

    /**
     * 短信发送
     * @param request
     * @return
     */
    @PostMapping("sendSms")
    public ResultModel<Boolean> sendSms(@RequestBody SendSmsCodeRequest request){
        return homeService.sendSms(request);
    }

    /**
     * 短信登录
     * @param request
     * @return
     */
    @PostMapping("crmPcLoginBySms")
    public ResultModel<LoginResponse> crmPcLoginBySms(@RequestBody WxLoginRequest request){
        return homeService.crmPcLoginBySms(request);
    }

    @PostMapping("getCompanyListByPhone")
    public ResultModel<List<CompanyModel>> getCompanyListByPhone(@RequestBody SendSmsCodeRequest request){
        return homeService.getCompanyListByPhone(request);
    }
}
